package com.ymatou.iapi.sellertrading.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellertrading.service.DiscountorderCall;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;

public class Ts_Discountorder {
	private static DiscountorderCall discountorderCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订单调价");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new DiscountorderCall().getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_001() {
		Logger.start(true, "常规操作下单后修改订单价格和运费金额");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.SUCCESS, ret.get("Code").toString(),
					"验证Code返回");
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			Logger.verifyEquals(freight,
					database.selectOrder(m).get(0).get("fFreight"),
					"验证Freight与输入相同");
			//Logger.verifyEquals("21.00", database.selectOrder(m).get(0).get("fOldFreight").toString(), "验证fOldFreight与输入相同");
			Logger.verifyEquals(discount,
					database.selectOrder(m).get(0).get("fOrderDiscount"),
					"验证discount与输入相同");
			//Logger.verifyEquals("0.00", database.selectOrder(m).get(0).get("fOldDiscount").toString(), "验证fOldDiscount与输入相同");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_002() {
		Logger.start(true, "请求地址中没有输入userid，请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("用户信息错误", ret.get("Msg").toString(),
					"验证返回Msg，应该提示用户信息错误");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_003() {
		Logger.start(true, "请求地址中没有输入sellerId，请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("用户信息错误", ret.get("Msg").toString(),
					"验证返回Msg，应该提示用户信息错误");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_004() {
		Logger.start(true, "请求报文中，订单ID为null，请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", null);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("操作失败", ret.get("Msg").toString(), "验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_005() {
		Logger.start(true, "订单号不存在，修改订单价格和运费失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", 777);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("订单号777不存在", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_006() {
		Logger.start(true, "订单不属于当前买手，操作失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			Integer testUserId = userId + 1;
			//发送请求
			discountorderCall = new DiscountorderCall(testUserId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("用户" + testUserId + "不是订单" + orderId + "的所有者",
					ret.get("Msg").toString(), "验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_007() {
		Logger.start(true, "当前订单买家操作调价，请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(userId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("用户" + userId + "不是订单" + orderId + "的所有者", ret
					.get("Msg").toString(), "验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_008() {
		Logger.start(true, "修改订单价格为负数,且小于订单价格，请求成功");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			discount = discount.multiply(new BigDecimal(-1));
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.SUCCESS, ret.get("Code").toString(),
					"验证Code返回");
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			Logger.verifyEquals(freight,
					database.selectOrder(m).get(0).get("fFreight"),
					"验证Freight与输入相同");
			Logger.verifyEquals(discount,
					database.selectOrder(m).get(0).get("fOrderDiscount"),
					"验证discount与输入相同");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_009() {
		Logger.start(true, "不调整运费的情况下，减少订单金额，减少到0，请求不通过");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = placeOrderResp.getFreight();

			Logger.comment("修改前，订单价格为：" + price + "，运费价格为：" + freight);
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal discount = price.multiply(new BigDecimal(-1));
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("订单金额+折扣金额必须大于0", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_010() {
		Logger.start(true, "不调整运费的情况下，减少订单金额，减到负数，请求不通过");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = placeOrderResp.getFreight();

			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal discount = price.multiply(new BigDecimal(-2));
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("订单金额+折扣金额必须大于0", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_011() {
		Logger.start(true, "不调整 订单金额的情况下，调整运费，将运费设置为负数，请求不通过");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = placeOrderResp.getFreight();
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			freight = freight.multiply(new BigDecimal(-2));
			updateMap.put("Discount", 0);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("运费不能小于0", ret.get("Msg").toString(), "验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_012() {
		Logger.start(true, "不调整 订单金额的情况下，调整运费，将运费设置为0，设置成功");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = placeOrderResp.getFreight();

			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("Discount", 0);
			updateMap.put("Freight", 0);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.SUCCESS, ret.get("Code").toString(),
					"验证Code返回");

			//数据验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			Logger.verifyEquals("0.00",
					database.selectOrder(m).get(0).get("fFreight").toString(),
					"验证Freight与输入相同");
			Logger.verifyEquals("0.00",
					database.selectOrder(m).get(0).get("fOrderDiscount")
							.toString(), "验证discount与输入相同");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_013() {
		Logger.start(true, "不调整订单金额的情况下，调整运费，将运费设置为10000，设置成功");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = new BigDecimal(10000).setScale(2,
					BigDecimal.ROUND_DOWN);
			Logger.comment("前置-常规下单成功");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			freight = freight.multiply(new BigDecimal(10));
			updateMap.put("Discount", 0);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.SUCCESS, ret.get("Code").toString(),
					"验证Code返回");

			//数据验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			Logger.verifyEquals(freight,
					database.selectOrder(m).get(0).get("fFreight"),
					"验证Freight与输入相同");
			Logger.verifyEquals("0.00",
					database.selectOrder(m).get(0).get("fOrderDiscount")
							.toString(), "验证discount与输入相同");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_014() {
		Logger.start(true, "调整订单金额和运费，订单降价，降价高于订单原价，小于订单原价加调整的运费， 请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			BigDecimal price = placeOrderResp.getPayAmount();
			BigDecimal freight = placeOrderResp.getFreight();
			Logger.comment("前置-常规下单成功");

			//组织报文
			freight = freight.multiply(price.multiply(new BigDecimal(3)));
			price = price.multiply(new BigDecimal(-2));

			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("Discount", price);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回");
			Logger.verifyEquals("订单金额+折扣金额必须大于0", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_015() {
		Logger.start(true, "当前订单为已付款待接单状态，修改订单价格运费，请求失败");
		try {
			//创建订单
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();
			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal price = placeOrderResp.getPayAmount();
			new OrderCallService().orderPayRequest(userId, price, tradingId);
			Logger.comment("下单并支付成功，已付款订单准备完毕");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("当前订单状态不能修改价格", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_016() {
		Logger.start(true, "当前订单使用了优惠券，修改价格运费，请求失败");
		try {
			//领取优惠券,下单
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			BigDecimal couponValue = new BigDecimal(10);
			String couponCode = new CouponCallService().receiveCouponInfo(
					sellerId, userId, couponValue);
			Map map = new OrderCallService().createM2cOrder(couponCode,
					couponValue);

			sellerId = (Integer) map.get("sellerId");
			userId = (Integer) map.get("userId");
			int orderId = (Integer) map.get("orderId");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.FAILED201, ret.get("Code").toString(),
					"验证Code返回201");
			Logger.verifyEquals("当前订单使用了优惠券,不可修改价格", ret.get("Msg").toString(),
					"验证返回Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Discountorder_017() {
		Logger.start(true, "一个订单下有多个商品，修改订单价格和运费成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			Map map = new OrderCallService().createBatchM2cOrder(3);
			int orderId = ((JSONArray) map.get("orderIds")).getInt(0);
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");

			//组织报文
			Map<String, Object> updateMap = new HashMap<String, Object>();
			BigDecimal freight = new BigDecimal(Math.random() * 10).setScale(2,
					BigDecimal.ROUND_DOWN);
			BigDecimal discount = new BigDecimal(Math.random()).setScale(2,
					BigDecimal.ROUND_DOWN);
			updateMap.put("Discount", discount);
			updateMap.put("Freight", freight);
			updateMap.put("OrderId", orderId);

			//发送请求
			discountorderCall = new DiscountorderCall(sellerId, userId);
			JSONObject ret = discountorderCall.callAndGetReturnData(updateMap);

			//断言
			Logger.verifyEquals(ECode.SUCCESS, ret.get("Code").toString(),
					"验证Code返回200");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}
